#include "stdafx.h"
#include "BasicInputMethodMgr.h"
#include <ShlObj.h>
#include <Shlwapi.h>

#pragma comment(lib,"imm32.lib")

namespace BasicSkinView
{
	CBasicInputMethodMgr::CBasicInputMethodMgr()
		:m_hWnd(NULL)
		,m_hImcPrev(NULL)
	{

	}

	CBasicInputMethodMgr::~CBasicInputMethodMgr()
	{
	}

	void CBasicInputMethodMgr::Attach( HWND hWnd )
	{
		m_hWnd = hWnd;
	}

	void CBasicInputMethodMgr::Dettach()
	{
		m_hWnd = NULL;
	}

	void CBasicInputMethodMgr::EnableDiableIME( bool bEnable )
	{
		if(!m_hWnd)
			return;

		if(false == bEnable)
		{
			//IME should be disabled
			HIMC hImc = ImmGetContext(m_hWnd);
			if(hImc!=NULL)
			{
				ImmReleaseContext(m_hWnd,hImc);
				m_hImcPrev = ImmAssociateContext(m_hWnd,NULL);
			}
		}else
		{
			//IME should be enabled
			if(m_hImcPrev!=NULL)
			{
				m_hImcPrev = ImmAssociateContext(m_hWnd,m_hImcPrev); 
			}
		}
	}

	HIMC CBasicInputMethodMgr::IMM_ImmGetContext()
	{
		if(m_hWnd)
		{
			return ImmGetContext(m_hWnd);
		}
		return NULL;
	}
}
